#ifndef _RINGBUFFER_H
#define _RINGBUFFER_H

#include "common_def.h"
#include <stdio.h>

typedef struct
{
    uint8_t *buffer; //必须是2的幂次倍
    uint32_t size;
    uint32_t read_ptr;
    uint32_t write_ptr;
}ringBuffer_t;

/**
 * min - 比较获取最小值函数
 * @argc1: 第一个数
 * @argc2: 第二个数
 * 
 * return val:最小的那个数
 */
uint32_t min(uint32_t argc1,uint32_t argc2);

/**
 * ringBufferInit - 初始化环形缓冲区
 * @ringBuff: 要初始化的结构体指针
 * @srcBuff:  缓冲区实体
 * @size:     缓冲区大小
 * 
 * return val:SUCC || FAIL
 */
uint8_t ringBufferInit(ringBuffer_t *ringBuff,uint8_t *srcBuff,size_t size);

/**
 * ringBufferIsEmpty - 判断环形缓冲区是否空
 * @buff: 结构体指针
 * 
 * return val:SUCC || FAIL
 */
uint8_t ringBufferIsEmpty(ringBuffer_t *buff);

/**
 * ringBufferIsFull - 判断环形缓冲区是否满
 * @buff: 结构体指针
 * 
 * return val:SUCC || FAIL
 */
uint8_t ringBufferIsFull(ringBuffer_t *buff);

/**
 * ringBufferWrite - 向缓冲区写入
 * @ringBuff: 结构体指针
 * @srcBuff : 要写入的数据
 * @writeSize:要写入数据的长度
 * 
 * return val:实际写入长度
 */
uint32_t ringBufferWrite(ringBuffer_t *ringBuff,uint8_t *srcBuff,size_t writeSize);

/**
 * ringBufferRead - 向缓冲区读取
 * @ringBuff: 结构体指针
 * @destBuff : 读取后存放的位置
 * @readSize:要读取数据的长度
 * 
 * return val:实际读取长度
 */
uint32_t ringBufferRead(ringBuffer_t *ringBuff,uint8_t *destBuff,size_t readSize);

#endif